package com.mowh.multithreading.active.object.active.active.object;

/**
 * @author mowh1gd
 * @create 2023/11/28 16:00
 */
class FutureResult<T> extends Result<T> {//Future模式，有互斥操作
    private Result<T> result;
    private boolean ready = false;

    public synchronized void setResult(Result<T> result) {
        this.result = result;
        this.ready = true;
        notifyAll();
    }

    @Override
    public synchronized T getResultValue() {
        while (!ready) {//非守护条件
            try {
                wait();
            } catch (InterruptedException e) {
            }
        }
        return result.getResultValue();
    }
}
